package simpleGui;

import java.awt.CheckboxMenuItem;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class GuiCheckboxGroup implements ItemListener {
	

		private HashMap<String,GuiCheckButton> items = new HashMap<String,GuiCheckButton>();

		public void add(GuiCheckButton cbmi) {
			cbmi.addItemListener(this);
			items.put(cbmi.getLabel(),cbmi);
		}

		@Override
		public void itemStateChanged(ItemEvent e) {
			if (e.getStateChange() == ItemEvent.SELECTED) {
				Object itemAffected = e.getSource();
				
				for (GuiCheckButton item : items.values()) {
					if (item != itemAffected)
						item.state=false;
				}
			}
		}

		public void selectItem(GuiCheckButton itemToSelect) {
			for (GuiCheckButton item : items.values()) {
				item.state=item == itemToSelect;
			}
		}

		public GuiCheckButton getSelectedItem() {
			for (GuiCheckButton item : items.values()) {
				if (item.state)
					return item;
			}
			return null;
		}
		
		public boolean containsItem(Object obj){
			return items.containsValue(obj);
		}

		public HashMap<String, GuiCheckButton> getItems() {
			return items;
		}

		public GuiCheckButton getGuiCheckButton(Object arg0) {
			return items.get(arg0);
		}

		
	
}
